#include "stack.h"

void stackinit(struct stack* ok) {
	int* tmp = (int*)malloc(sizeof(int) * 4);
	ok->a = tmp;
	ok->capacity = 4;
	ok->top = 0;
}
bool check(struct stack* ok) {
	return ok->top == ok->capacity;
}

void stackpush(struct stack* ok, int x) {
	assert(ok);
	if (check(ok)) {
		int* tmp = (int*)realloc(ok->a,sizeof(int) * ok->capacity * 2);
		ok->a = tmp;
		ok->capacity *= 2;
	}
	
	ok->a[ok->top] = x;
	ok->top++;
}
void stackpop(struct stack* ok){
	assert(ok);
	assert(!stackempty(ok));
	ok->top--;
}

int stacksize(struct stack* ok) {
	assert(ok);
	assert(!stackempty(ok));
	return ok->top;
}


bool stackempty(struct stack* ok) {
	return ok->top==0;
}
int stacktop(struct stack* ok) {
	assert(ok);
	assert(!stackempty(ok));
	return ok->a[ok->top - 1];
}




int main() {
	struct stack ok;
	stackinit(&ok);

	stackpush(&ok, 1);
	stackpush(&ok, 2);
	stackpush(&ok, 3);
	stackpush(&ok, 4);
	stackpush(&ok, 5);






	while (stackempty(&ok)){
		int tmp = stacktop(&ok);
		printf("%d ", tmp);
		stackpop(&ok);
	}
	

	return 0;
}